﻿using Aweber.Entity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Aweber;
using System.Configuration;

namespace UnitTests
{
    
    
    /// <summary>
    ///This is a test class for ListTest and is intended
    ///to contain all ListTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ListTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for List Constructor
        ///</summary>
        [TestMethod()]
        public void ListConstructorTest()
        {
            MockAdapter adapter = null;
            List target = new List(adapter);
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for campaigns
        ///</summary>
        [TestMethod()]
        public void campaignsTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API api = new API(appId, new MockAdapter());
            api.process_appId_token(ConfigurationManager.AppSettings["AweberToken"]);

            Account account = api.getAccount();

            List target = account.lists().entries[0];
                        
            BaseCollection<Campaign> actual;
            actual = target.campaigns();
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.total_size >= 0);

           
        }

        /// <summary>
        ///A test for subscribers
        ///</summary>
        [TestMethod()]
        public void subscribersTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API api = new API(appId, new MockAdapter());
            api.process_appId_token(ConfigurationManager.AppSettings["AweberToken"]);
            Account account = api.getAccount();

            List target = account.lists().entries[0];

            BaseCollection<Subscriber> actual;
            actual = target.subscribers();
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.total_size >= 0);
        }

        /// <summary>
        ///A test to see that all properties are loaded in the campaign
        ///</summary>
        [TestMethod()]
        public void ListPropertyTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API api = new API(appId, new MockAdapter());
            api.process_appId_token(ConfigurationManager.AppSettings["AweberToken"]);

            Account target = api.getAccount();

            List list = target.lists().entries[0];

            Assert.IsNotNull(list, "You need a list in your account to test this properly");

            Assert.IsFalse(String.IsNullOrEmpty(list.campaigns_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(list.custom_fields_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(list.custom_subscribers_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(list.web_form_split_tests_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(list.web_forms_collection_link));

            Assert.IsTrue(list.total_subscribed_subscribers >= 0);
            Assert.IsTrue(list.total_subscribers >= 0);
            Assert.IsTrue(list.total_subscribers_subscribed_today >= 0);
            Assert.IsTrue(list.total_subscribers_subscribed_yesterday >= 0);
            Assert.IsTrue(list.total_unconfirmed_subscribers >= 0);
            Assert.IsTrue(list.total_unsubscribed_subscribers >= 0);

        

        }

    }
}
